﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using LeakView.common;
using LeakView.service;

namespace LeakView.misc.view
{
    public partial class FormMiscHistory : Form
    {

        private TreeNode selectedNode = null;

        public FormMiscHistory()
        {
            InitializeComponent();
            HideTabcontrolLabel(this.tabControl1);
        }

        public void HideTabcontrolLabel(TabControl tabControl1)
        {
            tabControl1.Appearance = TabAppearance.FlatButtons;
            tabControl1.SizeMode = TabSizeMode.Fixed;
            for (int i = 0; i < tabControl1.TabPages.Count; i++)
            {
                tabControl1.TabPages[i].Text = "";
            }
            tabControl1.ItemSize = new Size(0, 1);
        }

        private void FormMiscHistory2_Load(object sender, EventArgs e)
        {
            this.flowStatisticsGridView1.initialize();


            var nodes = treeView1.Nodes.Find("SSSJ", true);
            this.SelectTheNode(nodes.First());

            treeView1.ExpandAll();
        }

        private void SelectTheNode(TreeNode node)
        {
            if (selectedNode != null)
            {
                selectedNode.BackColor = Color.Transparent;
            }

            selectedNode = node;

            if(selectedNode == null)
            {
                return;
            }

            selectedNode.BackColor = Color.SteelBlue;

            switch (node.Text)
            {
                case "实时数据":
                    this.tabControl1.SelectedIndex = 3;
                    break;

                case "累积数据":
                    this.tabControl1.SelectedIndex = 10;
                    break;

                case "瞬时输差":
                    this.tabControl1.SelectedIndex = 4;
                    break;
                case "10分钟输差":
                    this.tabControl1.SelectedIndex = 5;
                    break;
                case "30分钟输差":
                    this.tabControl1.SelectedIndex = 6;
                    break;
                case "60分钟输差":
                    this.tabControl1.SelectedIndex = 7;
                    break;

                case "压力流量":
                    this.tabControl1.SelectedIndex = 8;
                    break;

                default:
                    this.tabControl1.SelectedIndex = 0;
                    break;
            }

        }

        private void TreeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if(e.Node.Nodes.Count > 0)
            {
                return;
            }

            SelectTheNode(e.Node);

        }

        private void TreeView1_BeforeSelect(object sender, TreeViewCancelEventArgs e)
        {
            if (e.Node.Nodes.Count > 0)
            {
                e.Cancel = true;
                return;
            }
        }

        private void TreeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            SelectTheNode(e.Node);
        }
    }
}
